var settingss ={
    view: {
        addHoverDom: addHoverDom,
        removeHoverDom: removeHoverDom,
        selectedMulti: false
    },
    check: {
        enable: true,
        chkStyle: "radio",//值为checkbox或者radio表示
        radioType:"all",
        chkboxType: {"Y": "", "N": ""}//表示父子节点的联动效果，不联动
    },
    data: {
        simpleData: {
            enable: true
        }
    },
    edit: {
        enable: true,
        editNameSelectAll:true,
        removeTitle:'删除'
    },
    callback:{
        beforeRemove:beforeRemove,//点击删除时触发，用来提示用户是否确定删除
        onCheck:onCheck,
        onRemove:onRemove,//删除节点后触发，用户后台操作
    }

}
function addHoverDom(treeId, treeNode) {
    console.log(treeNode.pid+","+treeNode.id+","+treeId+",id长度"+treeNode.id.length)
    var sObj = $("#" + treeNode.tId + "_span");
    if (treeNode.editNameFlag || $("#addBtn_"+treeNode.tId).length>0) return;
    var addStr = "<span class='button add' id='addBtn_" + treeNode.tId
        + "' title='添加节点' onfocus='this.blur();'></span>";
    sObj.after(addStr);
};
function removeHoverDom(treeId, treeNode) {
    $("#addBtn_"+treeNode.tId).unbind().remove();
};
function beforeRemove(treeId, treeNode) {
    if(confirm("确认删除?\n将会删除下面的所有目录！")){
        if(treeNode.isParent){
            alert("该目录下面还有子目录，请从最底层目录开始删除!");
            return false;
        }
        return true;
    }
    return false;
}
function onRemove(e, treeId,treeNode) {
    $.ajax({
        type: "get",
        url: "removeProject",
        data: "bmDm=" + treeNode.id,
        success: function (data) {
            if (data.result){
                alert("删除成功")
            }else{
                alert("删除失败，后台有错误日志")
            }
        },
        error : function() {
            alert("删除失败")
        }
    })
}
function getTree(){
    $.getJSON("getTree",function(response){
       var zTree = $.fn.zTree.init($("#tree"),settingss,response)
        zTree.expandAll(true)
    })
}

$(function (){
    //生成树
    getTree()
    $(".form_datetime").datetimepicker({
        format: "yyyy-mm-dd hh:ii",
        language : 'zh-CN',
        weekStart: 1,
        todayBtn:  1,
        autoclose: 1,
        todayHighlight: 1,
        startView: 2,
        forceParse: 0,
        showMeridian: 1,
        initialDate : new Date(),
        pickerPosition:'top-right'
    })
})
function onCheck(e,treeId,treeNode){
    var $update = $('#update')
    $update.empty()
    $update.append("<a class='btn btn-info' href='#modal-container' data-toggle='modal' onclick=\"getUpdatemodal('"+treeNode.id+"')\">修改</a>")
}

